var orderDetail = {
	init :function(){
		var data = window.sessionStorage.getItem('orderDetail'),
		ids = JSON.parse(data).id;
		console.log(ids);
		app.ajax(
			'/Member/Index/order_details',
			{
				order_id : ids
			},function(res){
				if(res.code == 200){
					app.tpl($('.order-detail'),'tpl-order-detail',res);
				}
			}
		);
	}
}

footer.init();
header.init('订单详情');
orderDetail.init();

window.onload = function(){
		$('body').on('click','.order-status .topay',function(){
		var ids = $(this).attr('data-id'),
		type = 1;
		
		var ua = window.navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i) != 'micromessenger'){
			type = 1;
		}else{
			type = 2;
		}

		app.ajax(
			'/Member/Index/order_pay',
			{
				order_id : ids,
				payTypeId : type
			},function(res){
				if(res.code ==200){
					$('body').html(res.html);
				}else{
					layer.msg('网络忙请稍候再试');
				}
			}
		);
		return false;
	});
	
	$('body').on('click','.order-status .cancel',function(){
		var ids = $(this).attr('data-id');
		var t = $(this);
		layer.open({
			content:'确定要取消订单吗？',
			btn:['确定','取消'],
			shadeClose:false,
			yes:function(index){
				layer.close(index);
				app.ajax(
					'/Member/Index/order_clear',
					{
						order_id : ids
					},function(res){
						if(res.code == 200){
							layer.msg('取消订单成功');
							$(t).parents('.bill-head').find('h2').text('已取消');
							$(t).parent('.order-status').remove();
						}else{
							layer.msg(res.msg);
						}
					}
				);
			}
		});
		return false;
		
	});
	
	$('body').on('click','.product-mess',function(){
		var ids=$(this).attr('data-goodsid');
		app.open('productDetail.html','productDetail',{id:ids},window.location.href,document.body.scrollTop);
	});
}
